package com.tarena.lbs.common.marketing.converter;

import com.tarena.lbs.base.protocol.pager.BasePageList;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.marketing.bo.UserReceiveCouponBO;
import com.tarena.lbs.pojo.marketing.dos.UserReceiveCouponDO;
import com.tarena.lbs.pojo.marketing.query.UserCouponQuery;
import com.tarena.lbs.pojo.marketing.vo.UserReceiveCouponVO;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UserReceiveCouponConverter {

    public PageResult<UserReceiveCouponVO> assemblePageVOS(BasePageList<UserReceiveCouponBO> bos, UserCouponQuery query) {
        if (bos == null || bos.getTotal() == 0) {
            return null;
        }
        PageResult<UserReceiveCouponVO> result = new PageResult<>();
        List<UserReceiveCouponVO> vos = new ArrayList<>();
        for (UserReceiveCouponBO temp : bos.getList()) {
            UserReceiveCouponVO vo = new UserReceiveCouponVO();
            BeanUtils.copyProperties(temp,vo);
            vos.add(vo);
        }
        result.setTotal(bos.getTotal());
        result.setObjects(vos);
        result.setPageNo(query.getPageNo());
        result.setPageSize(query.getPageSize());
        return result;
    }

    public UserReceiveCouponVO bo2vo(UserReceiveCouponBO bo) {
        if (bo == null) {
            return null;
        }
        UserReceiveCouponVO vo = new UserReceiveCouponVO();
        BeanUtils.copyProperties(bo,vo);
        return vo;
    }

    public UserReceiveCouponBO do2bo(UserReceiveCouponDO tempDo) {
        if (tempDo == null) {
            return null;
        }
        UserReceiveCouponBO bo = new UserReceiveCouponBO();
        BeanUtils.copyProperties(tempDo,bo);
        return bo;
    }

    public List<UserReceiveCouponBO> dos2bos(List<UserReceiveCouponDO> tempDos) {
        if (tempDos == null) {
            return null;
        }
        List<UserReceiveCouponBO> bos = new ArrayList<>();
        for (UserReceiveCouponDO tempDo : tempDos) {
            UserReceiveCouponBO bo = new UserReceiveCouponBO();
            BeanUtils.copyProperties(tempDo, bo);
            bos.add(bo);
        }
        return bos;
    }
}
